package com.opennetexam.manager.mapper;

import com.opennetexam.manager.dto.ExamineeExamPaperItem;
import com.opennetexam.manager.sqlprovider.ExamineeExamPaperItemProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 奶茶
 * Created on 2017/11/28.
 */
@Mapper
public interface ExamineeExamPaperItemMapper {

    @Select("DELETE eepi FROM \n" +
            "ExamineeExamPaperItem eepi  \n" +
            "LEFT JOIN ExamineeExamPaper eep ON eepi.ExamPaperInfoID = eep.ExamPaperInfoID \n" +
            "WHERE eep.ExamPlanInfoID = #{planId}")
    List<ExamineeExamPaperItem> delExamineeExamPaperItemByPageInfoIds(@Param("planId") String planId);

    @Insert("INSERT INTO ExamineeExamPaperItem (ExamPaperInfoID,PaperID,ItemID,ItemContent) VALUES (#{examPaperInfoID},#{paperID},#{itemID},#{itemContent})")
    Integer insertExamineePaperItem(ExamineeExamPaperItem paperItem);

    //@Select("SELECT * FROM ExamineeExamPaperItem WHERE ExamPaperInfoID = #{examPaperInfoID}")
    @Select("SELECT examineepaper.examPaperInfoID,paper.PaperID,item.ItemID,item.ItemContent\n" +
            "FROM ExamineeExamPaper AS examineepaper\n" +
            "JOIN ExamPaper AS paper ON examineepaper.ExamPaperID = paper.ExamPaperID\n" +
            "JOIN ExamPaperItem AS item ON item.PaperID = paper.PaperID\n" +
            "WHERE examineepaper.examPaperInfoID = #{examPaperInfoID}")
    List<ExamineeExamPaperItem> findExamineePaperItemByExamPaperInfoId(@Param(value = "examPaperInfoID") String examPaperInfoID);

    @DeleteProvider(type = ExamineeExamPaperItemProvider.class,method = "deleteExamineeExamPaperItems")
    Integer deleteExamineeExamPaperItems(@Param(value = "items") List<ExamineeExamPaperItem> items);

    @Select("SELECT * FROM ExamineeExamPaperItem WHERE ItemID = #{itemId} LIMIT 1")
    ExamineeExamPaperItem getPaperItemByItemId(@Param(value = "itemId") String itemId);

}
